<template>
  <div>
    <HomeWork1
      @delete="delFn"
      @addNum="addFn"
      @subNum="subFn"
      @check="checkFn"
      :arr="goodList"
    ></HomeWork1>
  </div>
</template>

<script>
import HomeWork1 from "./components/homework1";
export default {
  components: {
    HomeWork1,
  },
  data() {
    return {
      goodList: [
        {
          name: "诸葛亮",
          price: 1000,
          num: 1,
          checked: false,
        },
        {
          name: "蔡文姬",
          price: 1500,
          num: 1,
          checked: false,
        },
        {
          name: "妲己",
          price: 2000,
          num: 1,
          checked: false,
        },
        {
          name: "鲁班",
          price: 2200,
          num: 1,
          checked: false,
        },
      ],
    };
  },
  methods: {
    checkFn(val) {
      this.goodList.forEach((obj) => (obj.checked = val));
    },
    subFn(ind) {
      this.goodList[ind].num && this.goodList[ind].num--;
    },
    addFn(ind) {
      this.goodList[ind].num++;
    },
    delFn(ind) {
      this.goodList.splice(ind, 1);
    },
  },
};
</script>

<style>
</style>